package io.kiki.sba.registry.server.clientInterface.converter.pb;

import io.kiki.sba.registry.common.model.client.pb.RegisterResponsePb;
import io.kiki.sba.registry.core.model.RegisterResponse;


public class RegisterResponseConvertor {

    public static RegisterResponse convert2Java(RegisterResponsePb registerResponsePb) {

        if (registerResponsePb == null) {
            return null;
        }

        RegisterResponse registerResponse = new RegisterResponse();

        registerResponse.setMessage(registerResponsePb.getMessage());
        registerResponse.setRefused(registerResponsePb.getRefused());
        registerResponse.setRegistId(registerResponsePb.getRegistId());
        registerResponse.setSuccess(registerResponsePb.getSuccess());
        registerResponse.setVersion(registerResponsePb.getVersion());

        return registerResponse;
    }

    public static RegisterResponsePb convert2Pb(RegisterResponse registerResponseJava) {

        if (registerResponseJava == null) {
            return null;
        }

        RegisterResponsePb.Builder builder = RegisterResponsePb.newBuilder();

        if (null != registerResponseJava.getMessage()) {
            builder.setMessage(registerResponseJava.getMessage());
        }
        if (null != registerResponseJava.getRegistId()) {
            builder.setRegistId(registerResponseJava.getRegistId());
        }
        builder.setVersion(registerResponseJava.getVersion());
        builder.setRefused(registerResponseJava.isRefused());
        builder.setSuccess(registerResponseJava.isSuccess());

        return builder.build();
    }
}
